<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;

/**
 * SignIn 签到
 */
class SignIn extends Base
{

    public function logic()
    {

        $uid = $this->uid;
        $object = DB::select("SELECT * FROM t_signin_rec where uid = $uid AND TO_DAYS(create_time) = TO_DAYS(NOW()) LIMIT 0,1;");
        if (count($object) > 0) {
            return $this->returnError(1, "你今天已经签到了.");
        }
        $m_day       = date("d");
        $data        = array();
        if (DB::table('t_signin_rec')->insert(["uid" => $uid, "day" => $m_day])) {
            $add_gold         = 1000;
            $data["add_gold"] = $add_gold;
            $ret              = $this->grant_golds($uid, $add_gold, "签到奖励", (string)$m_day);
			if (!$ret) {
                return $this->returnError(2, "签到奖励金币时，服务器发生数据错误.");
            }
			return $this->returnData($data);
		} else {
            return $this->returnError(1, "签到 服务器数据操作错误.");
        }
    }

}